<?php
session_start();
?>


<?php
$username = $_SESSION['username'];
if($username==null || $username== ""|| $username == "")
{
	header('Location: http://172.26.195.159/checklist/php/logout.php');
}
	$_SESSION['crno'] = "";
	$_SESSION['reviewer'] = "";
	$_SESSION['errmsg'] = "";
	$_SESSION['master'] = "";
	$_SESSION['logintype'] ="";
?>



<html>
<head>
<script language=javascript >
function openDesignNote()
{
if(document.getElementById("design_note_reqd").value=="Yes")
{
    var id = document.getElementById("id").value;
    if(id=="" || id==null){
	document.getElementById("design_note_reqd").value="No";
	alert("Please enter the CR/FEAT id");
	}
		
	else
	{
	var url="http://172.26.195.159/checklist/php/designnote.php?id=";
	
	popupWindow = window.open(url+id,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
	}
	
}
}

function validate()
{
	try
	{
	var s_internal_idce =document.getElementById("internal_idce_number").value;
	
	var str_loc = document.getElementById("line_of_code").value;
	
	
	if(s_internal_idce.search(" ") >=0 )
	{
		alert("Internal IDCE number contains space character");
		return false;
	}
	
	var n_internal_idce=parseInt(s_internal_idce);
	
	if(isNaN(n_internal_idce) )
	{
		alert("Please enter valid internal IDCE number");
		return false;
	}
	
	var n_loc=parseInt(str_loc);
	
	if(isNaN(n_loc) )
	{
		alert("Please enter the lines of code in valid form.");
		return false;
	}
	
	str=document.getElementById("id").value;
	
	if(str.search(" ") >=0 )
	{
		alert("CR number contains space character");
		return false;
	}
	
	var elements=new Array();
	elements[0]="id";
	elements[1]="title";
	elements[2]="description";
	elements[3]="root_cause";
	elements[4]="solution";
	elements[5]="view_name";
	elements[6]="activity_name";
	elements[7]="patch_name";
	elements[8]="parcel_name";
	elements[9]="compile_dir";
	elements[10]="package_dir";
	elements[11]="domain";
	elements[12]="baseline";
	elements[13]="milestone";
	elements[14]="complexity";
	elements[15]="line_of_code";
	
	
	for(i=0;i<=15 ; i++ )
	{
		if(	document.getElementById(elements[i]).value == "" || document.getElementById(elements[i]).value == " " )
		{
			alert("Fields cannot be blank : "+ elements[i]);
			return false;
		}
	}
	
	if(document.getElementById("checklist_reviewer").value == "selectName")
	{
		alert("Please select valid Checklist reviewer");
		return false;
	}
	if(document.getElementById("pl").value == "selectName")
	{
		alert("Please select valid PL");
		return false;
	}
	if(document.getElementById("pm").value == "selectName")
	{
		alert("Please select valid PM");
		return false;
	}
	if(document.getElementById("dp_prime").value == "selectName")
	{
		alert("Please select valid DP Prime");
		return false;
	}
	if(document.getElementById("internal_idce_reviewer").value == "selectName")
	{
		alert("Please select valid Internal Reviewer");
		return false;
	}
	
	//If External IDCE reqd flag is true make it mandatory to have e_idce_name and e_idce_reviewer..
	
	if(document.getElementById("external_idce_reqd_yes").checked)
	{
		if(document.getElementById("external_idce_reviewer").value == "selectName")
		{
		alert("Please select valid External Reviewer");
		return false;
		}
	}
	
	if(document.getElementById("external_idce_reqd_yes").checked)
	{
	    var e_n = document.getElementById("external_idce_number").value;
		if(e_n == 0 || e_n == "" || e_n == " " || isNaN(e_n))
		{
		alert("Please enter valid External IDCE Number");
		return false;
		}
	}
	
	if(document.getElementById("domain").value == "Select Domain")
	{
		alert("Please select valid domain");
		return false;
	}
	
	
	
	}catch(err)
	{
		alert("error:"+err);
	}
	
}

function sort()
{

	try
	{
	sortselect(document.getElementById("internal_idce_reviewer"));
	sortselect(document.getElementById("external_idce_reviewer"));
	sortselect(document.getElementById("pl"));
	sortselect(document.getElementById("pm"));
	sortselect(document.getElementById("checklist_reviewer"));
	sortselect(document.getElementById("dp_prime"));
	}
	catch(err)
	{
		alert("error:"+err);
	}

}

function sortselect(selElem) 
{                
		var tmpAry = new Array();
                 for (var i=0;i<(selElem.options.length-1);i++) { 
                        tmpAry[i] = new Array();
                         tmpAry[i][0] = selElem.options[(i+1)].text;
                         tmpAry[i][1] = selElem.options[(i+1)].value;
                 }
                 tmpAry.sort();
                 while (selElem.options.length > 0) {
                     selElem.options[0] = null;
                 }
                 
                 var a = new Option("Select Name","selectName");
                 selElem.options[0]=a;
                 for (var i=0;i<tmpAry.length;i++) {
                         var op = new Option(tmpAry[i][0], tmpAry[i][1]);
                         selElem.options[(i+1)] = op;
                 }
                 return;
         
}


</script>

<title>CR, Feature Details</title>
</head>
<body bgcolor="#C9C299" onload="sort()" >
<table width=500 >
<tr>
<td><a href="welcome.php">Home </a></td>
<td><a href="logout.php" > Logout</a></td>
</tr>
</table>
<h3><font color="blue">CR/Feature Details</font></h3>

<?php include('./classes/employee.php'); ?>

<?php

$username = $_SESSION['username'];


//creating a connection.
$con = mysql_connect("localhost","root","");

if (!$con) {
    die('Could not connect: ' . mysql_error());
}


//collecting all employees
$employees  = array();

//collecting PL's
$employees_pl = array();

//collecting PM's
$employees_pm = array();

//collecting DP's
$employees_dp = array();

 // Select table
mysql_select_db("checklist", $con);
 
	//Feeding all employees.
 
    $result = mysql_query("select * from employees");   
	$i=0;
	while ($row = mysql_fetch_array($result))
    {
	    $emp = new employee();
		$emp->set_username($row['username']);
		$emp->set_fullname($row['fullname']);
		$emp->set_email($row['email']);
		$emp->set_role($row['role']);
		$employees[] = $emp;
    }
	
	//Feeding all PL's
	$result = mysql_query("select * from employees where role = 'PL'");   
	$i=0;
	while ($row = mysql_fetch_array($result))
    {
	    $emp = new employee();
		$emp->set_username($row['username']);
		$emp->set_fullname($row['fullname']);
		$emp->set_email($row['email']);
		$emp->set_role($row['role']);
		$employees_pl[] = $emp;
    }

	//Feeding PM's
	$result = mysql_query("select * from employees where role = 'PM'");   
	$i=0;
	while ($row = mysql_fetch_array($result))
    {
	    $emp = new employee();
		$emp->set_username($row['username']);
		$emp->set_fullname($row['fullname']);
		$emp->set_email($row['email']);
		$emp->set_role($row['role']);
		$employees_pm[] = $emp;
    }	
	
	//Feeding DP's
	$result = mysql_query("select * from employees where role = 'DP'");   
	$i=0;
	while ($row = mysql_fetch_array($result))
    {
	    $emp = new employee();
		$emp->set_username($row['username']);
		$emp->set_fullname($row['fullname']);
		$emp->set_email($row['email']);
		$emp->set_role($row['role']);
		$employees_dp[] = $emp;
    }	
	
    
?>

	
	
	
<form action="processCrDetails.php" method="post" name="crdetails" > 

<table width=75% height=100% cellpadding=15px cellspacing=10px>
    <tr>
    <td><b>Designer</b></td>
    <td><input type="text" name="designer" id="designer" value="<?php echo "".$_SESSION['fullname'] ?>" readonly="readonly" ></td>
    </tr>
    
    <tr>
	<td><b>CR/FEAT *</b></td>
	<td><input type=text name="id" id="id" ></td>
    </tr>
    
    <tr>
	<td><b>CR/FEAT Title*</b></td>
	<td><input name="title" size=50 id="title" ></td>
    </tr>
    
    <tr>
	<td><b>Description*</b></td>
	<td><textarea name="description" id="description" rows=5 cols=40></textarea></td>
    </tr>
    
    <tr>
    <td><b>Design Note Required</b></td>
    <td><select id="design_note_reqd" name="design_note_reqd" onchange="openDesignNote()">
    <option selected="selected" value="No">No</option>
    <option value="Yes">Yes</option>
    </select>
    </td>
    </tr>
    
    <tr>
	<td><b> Root Cause*</b></td>
	<td><textarea name="root_cause" id="root_cause" rows=5 cols=40></textarea></td>
    </tr>
    
    <tr>
	<td><b> Solution*</b></td>
	<td><textarea name="solution" id="solution" rows=5 cols=40></textarea></td>
    </tr>
    
    <tr>
	<td><b>View Name*</b></td>
	<td><input name="view_name" id="view_name" ></td>
    </tr>
    
    <tr>
	<td><b>Activity Name*</b></td>
	<td><input name="activity_name" id="activity_name" ></td>
    </tr>
    
    <tr>
	<td><b>Patch Back Required?</b></td>
	<td><select name="patch_back_reqd" id="patch_back_reqd" >
		<option selected="selected" >Yes</option>
		<option>No</option>
	    </select>
	</td>
    </tr>
    
    <tr>
	<td><b>Patch Name*</b></td>
	<td><input name="patch_name" id="patch_name" ></td>
    </tr>
    
    <tr>
	<td><b>Parcel Name(s)*</b></td>
	<td><input name="parcel_name" size=50 id="parcel_name"></td>
    </tr>
    
    <tr>
	<td><b>Compile Dir(s)*</b></td>
	<td><input name="compile_dir" id="compile_dir" size=50></td>
    </tr>
    
    <tr>
	<td><b>Package Dir(s)*</b></td>
	<td><input name="package_dir" id="package_dir" size=50></td>
    </tr>
    
    <tr>
	<td><b>BuildTargets*</b></td>
	<td><input name="build_target" id="build_target" size=50></td>
    </tr>
    
    <tr>
	<td><b>Checklist Reviewer*</b></td>
	<td>
	<select name="checklist_reviewer" id="checklist_reviewer">
	<option value="selectName" >Select Name</option>
	<?php
	foreach($employees as $emp)
	{
	?>
	<option value=<?php echo "".$emp->get_username(); ?> > <?php echo "".$emp->get_fullname(); ?> 
	</option>
	
	<?php 	} ?>
	
	
	</select>
	</td>
	</tr>
	
    <tr>
	<td><b>PL*</b></td>
	<td>
	
	<select name="pl" id="pl">
		
	<option value="selectName" >Select Name</option>
	<?php
	foreach($employees_pl as $emp)
	{
	?>
	<option value=<?php echo "".$emp->get_username(); ?> > <?php echo "".$emp->get_fullname(); ?> 
	
	</option>
	
	<?php 	} ?>
	
	</select>
	</td>
    </tr>
    
    <tr>
	<td><b>PM*</b></td>
	<td>
	<select name="pm" id="pm" >
	
	<option value="selectName" >Select Name</option>
	<?php
	foreach($employees_pm as $emp)
	{
	?>
	<option value=<?php echo "".$emp->get_username(); ?> > <?php echo "".$emp->get_fullname(); ?> </option>
	
	<?php 	} ?>
		
	</select>
	</td>
    </tr>
    
    <tr>
	<td><b>Patching Guidelines*</b></td>
	<td><textarea name="patching_guidelines" id="patching_guidelines" rows=5 cols=40></textarea></td>
    </tr>
    
    <tr>
    <td><b>DP prime*</b></td>
	<td>
	<select name="dp_prime" id="dp_prime">
	
	<option value="selectName" >Select Name</option>
	<?php
	foreach($employees_dp as $emp)
	{
	?>
	<option value=<?php echo "".$emp->get_username(); ?> > <?php echo "".$emp->get_fullname(); ?> 
	
	</option>
	
	<?php 	} ?>
	
	</select>
	</td>
    </tr>
    
	<tr>
    <td><b>Baseline*</b></td>
    <td><input type="text" id="baseline" name="baseline" ></td>
    </tr>
    
    <tr>
    <td><b>Milestone*</b></td>
    <td><input type="text" id="milestone" name="milestone" ></td>
    </tr>
    
    <tr>
    <td><b>Complexity*</b></td>
    <td>
    <select id="complexity" name="complexity" >
    <option value="High">High</option>
    <option value="Medium">Medium</option>
    <option value="Low" >Low</option>
    </select>
    </td>
    </tr>
    
    <tr>
    <td><b>Lines of Code*</b></td>
    <td><input type="text" id="line_of_code" name="line_of_code" ></td>
    </tr>
    
    <tr>
    <td><b>Selected Domain*</b></td>
    <td>
    <select id="domain" name="domain" >
    <option value="Select Domain">Select Domain</option>
    <option value="MTC">MTC</option>
    <option value="Kernel">Kernel</option>
    <option value="USM" >USM</option>
    <option value="FCAPS">FCAPS</option>
    <option value="NGW" >NGW</option>
    <option value="CA" >CA</option>
    <option value="SSG" >SSG</option>
    </select>
    
    </td>
    </tr>
    
    <tr>
    <td></td>
    </tr>
    
   
    <tr>
    <td><b>Internal IDCE number*</b></td>
    <td><input type="text" id="internal_idce_number" name="internal_idce_number" ></td>
    </tr>
    
    <tr>
	<td><b>Internal IDCE Reviewer*</b></td>
	<td>
	<select name="internal_idce_reviewer" id="internal_idce_reviewer">
	<option value="selectName" >Select Name</option>
	<?php
	foreach($employees as $emp)
	{
	?>
	<option value=<?php echo "".$emp->get_username(); ?> > <?php echo "".$emp->get_fullname(); ?> 
	</option>
	
	<?php 	} ?>
	
	</select>
	</td>
    </tr>

	<tr>
	<td><b>External IDCE required ?</b></td>
	<td>
	<input type="radio" name="external_idce_reqd" id="external_idce_reqd_yes" value="Yes"/>Yes
	<input type="radio" name="external_idce_reqd" id="external_idce_reqd_no" value="No" checked="checked"/>No
	</td></tr>
	

	 <tr>
    <td><b>External IDCE number</b></td>
    <td><input type="text" id="external_idce_number" name="external_idce_number" value="0"></td>
    </tr>
    
    <tr>
	<td><b>External IDCE Reviewer</b></td>
	<td>
	<select name="external_idce_reviewer" id="external_idce_reviewer">
	<option value="selectName">Select Name</option>
	<?php
	foreach($employees as $emp)
	{
	?>
	<option value=<?php echo "".$emp->get_username(); ?> > <?php echo "".$emp->get_fullname(); ?> 
	</option>
	
	<?php 	} ?>
	
	</select>
	</td>
    </tr>
	
	
    <tr>
    <td colspan=2 >
    <center>
	<input type="submit" name="submit" value="Proceed ->" onclick="return validate()" >
	</center>
	</td>
    </tr>
    
</table>
 
</form>

<h3>Fields marked(*) are mandatory</h3>
</body>
</html>